#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
struct tag
{
    int id;
    int layer;
};
vector<tag> v[1001]; //利用变长数组（向量）建立图的邻接表
int BFS(int id, int level)
{
    int visit[1001] = {0}; //访问标记
    queue<tag> que;
    int i;
    int count = 0; //记录转发次数
    for (i = 0; i < v[id].size(); ++i)
    {
        v[id][i].layer = 1;
        que.push(v[id][i]);
        visit[v[id][i].id] = 1;
    }
    while (!que.empty())
    {
        if (que.front().layer < level)
        {
            for (i = 0; i < v[que.front().id].size(); ++i)
            {
                if (visit[v[que.front().id][i].id] == 0 && v[que.front().id][i].id != id)
                { //若未被访问过，加入队列
                    v[que.front().id][i].layer = que.front().layer + 1;
                    que.push(v[que.front().id][i]);
                    visit[v[que.front().id][i].id] = 1;
                }
            }
        }
        que.pop();
        ++count;
    }
    return count;
}
int main()
{
    int N;
    scanf("%d", &N);
    int level;
    scanf("%d", &level);
    int count;
    int i, j, k;
    int id;
    tag nod;
    for (i = 1; i <= N; ++i)
    { //依次读入各用户的信息
        scanf("%d", &count);
        for (j = 0; j < count; ++j)
        { //把该用户添加到其关注用户的推送列表当中
            scanf("%d", &id);
            nod.id = i;
            v[id].push_back(nod);
        }
    }
    scanf("%d", &count);
    for (i = 0; i < count; ++i)
    {
        scanf("%d", &id);
        printf("%d\n", BFS(id, level));
    }
    return 0;
}
